
#include <xtd/functional>

namespace My {

template <typename T> 
CompositeProperty<T>::CompositeProperty(bool expanded) 
	: m_Expanded(expanded), m_Init(false)
{ 
}

template <typename T> 
CompositeProperty<T> & CompositeProperty<T>::DefaultExpanded(bool on) 
{ 
	m_Expanded = on; 
	return * this;
}

template <typename T> 
void CompositeProperty<T>::DoInit() const
{
	if (!m_Init) {
		const_cast<CompositeProperty<T> *>(this)->Init();
		m_Init = true;
	}
}

template <typename T> 
StructProperty<T>::~StructProperty()
{
	std::for_each(m_AutoCreated.begin(), m_AutoCreated.end(),
		xtd::deleter());
}

template <typename T> 
template <typename U>
PropertyImpl<U> & StructProperty<T>::Create(boost::shared_ptr< ReadWriteAccess<U> > pRW)
{
	PropertyImpl<U> * ptr = new My::Property<U>();
	m_AutoCreated.push_back(ptr);
	ptr->ReadWrite(pRW);
	return * ptr;
}


template <typename T> 
template <typename U>
PropertyImpl<U> & StructProperty<T>::Create(U T::* pMember)
{ 
	return Create<U>(My::ReadWrite(* this, pMember));
}

template <typename T> 
template <typename U>
PropertyImpl<U> & StructProperty<T>::CreatePersistent(boost::shared_ptr< ReadWriteAccess<U> > pRW)
{
	PropertyImpl<U> * ptr = new My::PersistentProperty<U>();
	m_AutoCreated.push_back(ptr);
	ptr->ReadWrite(pRW);
	return * ptr;
}


template <typename T> 
template <typename U>
PropertyImpl<U> & StructProperty<T>::CreatePersistent(U T::* pMember)
{ 
	return CreatePersistent<U>(My::ReadWrite(* this, pMember));
}

} // My
